package com.jxc.controller;

import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;


import net.sf.json.JSONArray;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import org.springframework.web.context.request.ServletRequestAttributes;

import com.jxc.mapper.UserMapper;
import com.jxc.po.User;
import com.jxc.util.DBUtil;
import java.net.URLDecoder;


@Controller
public class LoginController  {
	  @RequestMapping(value="/login")
	  public void login(User user,PrintWriter out) {  
		
		System.out.println("sdfa"+user.getUserid());

		SqlSession sqlSession = null;
		User rs=null;
		try {
			sqlSession = DBUtil.getSession();
			UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
			
			rs=userMapper.select(user);
			sqlSession.commit();
		} catch (Exception e) {
			sqlSession.rollback();
		} finally {
			DBUtil.closeSession(sqlSession);
		}
		
		ArrayList<User> kl=new ArrayList<User>();
		
		kl.add(rs);
		
		JSONArray jsonArray = JSONArray.fromObject(kl);
		out.print(jsonArray);
		
		
	  }  
	
}
